<?php
header('content-Type: text/html; charset=UTF-8');
$rows = array();

$id = isset($_GET['id'])?$_GET['id']:0;

try {
  $pdo = new PDO('mysql:dbname=study01;host=localhost','root','0000');
  $pdo->query("SET NAME utf8");
  $id = 2;
  $aql = 'select * from t_student where id='.$id;
  $stmt = $pdo->prepare($sql);
  $flag = $stmt->execute();

  $rows = $stmt->fetchAll();

  //var_dump($row);
  if($flag){
    echo"error.....";

  }

} catch (PDOException $e) {
echo 'Connection failed:' . $e->getMessage();
}

 ?>
 <!DOCTYPE html>
 <html>
   <head>
     <meta charset="utf-8">
     <title>课堂练习</title>
   </head>
   <body>
    <div>
      显示所有学生
    </div>
    <table border="1" style="width:100%">
      <tr>
        <td>
          ID
        </td>
        <td>
          姓名
        </td>
        <td>
          年龄
        </td>
        <td>
          性别
        </td>
      </tr>
      <?php
      foreach ($rows as $item): ?>
      <tr>
        <td>
          <?php echo $item['id']) ?>
        </td>
        <td>
          <?php echo $item['name']) ?>
        </td>
        <td>
          <?php echo $item['age']) ?>
        </td>
        <td>
          <?php echo $item['gender']== ? '男'：'女') ?>
        </td>
      </tr>
    <?php endforeach ?>
    </table>

   </body>
 </html>
